package com.guigu.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.pojo.ShopInfo;
import com.guigu.pojo.Users;
import com.guigu.pojo.WarehouseInfo;
import com.guigu.service.WarehouseInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/warehouseInfo/")
public class WarehouseInfoController {
    //自动注入
    @Autowired
    WarehouseInfoService warehouseInfoService;

    //分页查询
    @GetMapping("warehouseInfo.action")
    public Page<WarehouseInfo> queryAllShops(WarehouseInfo warehouseInfo,
                                        @RequestParam(value = "pageno",defaultValue = "1")Integer pageno,
                                        @RequestParam(value = "pagesize",defaultValue = "5")Integer pagesize){
        return warehouseInfoService.queryAllShops(warehouseInfo,pageno,pagesize);
    }

    //添加仓库，需要审核
    @PutMapping("warehouseInfo.action")
    public Map addWarehouseInfo(@RequestBody WarehouseInfo warehouseInfo){
        return  warehouseInfoService.addWarehouseInfo(warehouseInfo);
    }

    //审核仓库
    @PostMapping("checkWarehouseInfo.action")
    public Map checkWarehouseInfo(@RequestBody WarehouseInfo warehouseInfo){
        return  warehouseInfoService.checkWarehouseInfo(warehouseInfo);
    }

    //获取指定商品可以存放的仓库有哪些
    @GetMapping("assignWarehouseInfo.action")
    public List<WarehouseInfo> assignWarehouseInfo(ShopInfo shopInfo){
        return  warehouseInfoService.assignWarehouseInfo(shopInfo);
    }

    //仓库间货物调拨

    //仓库商品配置审批

    //仓库商品配置编辑

    //删除仓库
//    @DeleteMapping("assignWarehouseInfo.action")
//    public Map delWarehouseInfo(@RequestBody WarehouseInfo warehouseInfo){
//        return  warehouseInfoService.delWarehouseInfo(warehouseInfo);
//    }

    //根据id，获取仓库对象
    @GetMapping("queryWarehouseInfoById.action/{id}")
    @CrossOrigin
    public WarehouseInfo queryWarehouseInfoById(@PathVariable Integer id){
        return warehouseInfoService.queryWarehouseInfoById(id);
    }

    //根据商品id查询总数量
    @GetMapping("upNumByShopId.action/{id}")
    public Map queryUpNumByShopId(@PathVariable Integer id){
        return warehouseInfoService.queryUpNumByShopId(id);
    }

    //曹科 根据id查询仓库
    @GetMapping("queyrbyid.action")
    public WarehouseInfo queryWarehouseInfobyid(WarehouseInfo warehouseInfo){
        return warehouseInfoService.queryWarehouseInfobyid(warehouseInfo);
    }

    //曹科 根据页面传来的数据 来修改
    @PutMapping("amendWarehouseInfo.action")
    public Map amendWarehouseInfo(@RequestBody WarehouseInfo warehouseInfo){
        return warehouseInfoService.amendWarehouseInfo(warehouseInfo);
    }

    //曹科 根据id来删除  假删
    @PutMapping("querybyidUpdateWarehouseInfo.action/{id}")
    public Map querybyidUpdateWarehouseInfo(@PathVariable Integer id){
        System.out.println("-------"+id);
        return warehouseInfoService.querybyidUpdateWarehouseInfo(id);
    }

    // 曹科 根据仓库名查询是否有同样的仓库名
    @GetMapping("querybywarname.action")
    public Map querybywarname(WarehouseInfo warehouseInfo){
        return warehouseInfoService.querybywarname(warehouseInfo);
    }

    // 查询所有仓库
    @GetMapping("queryAllWarehouseInfo.action")
    public Page queryAllWarehouseInfo(WarehouseInfo warehouseInfo,
                                      @RequestParam(value = "pageno",defaultValue = "1")Integer pageno,
                                      @RequestParam(value = "pagesize",defaultValue = "5")Integer pagesize){
        return warehouseInfoService.queryAllWarehouseInfo(warehouseInfo,pageno,pagesize);
    }

 }
